/**
 * 
 */
package metalink.admin;

import java.util.ArrayList;

import javax.servlet.http.HttpSession;

import myutil.Connect;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import vo.CollegeResidentialVo;

/**
 * @author Sony
 *
 */
public class InsertIntoHostel extends ActionSupport{
	public String execute() {
		try {
			int count = 0;
			String query = "";
			Connect c = new Connect();
			HttpSession session = ServletActionContext.getRequest().getSession();
			ArrayList<CollegeResidentialVo> hostel_list = (ArrayList<CollegeResidentialVo>) session.getAttribute("uploaded_hostel_list");
			if (hostel_list != null) {
				for (CollegeResidentialVo vo : hostel_list) {
						query = "insert into college_residential(residential_name,residential_type,warden_id,warden_name,capacity) values('"
								+ vo.getResidential_name()
								+ "','"
								+ vo.getResidential_type()
								+ "',"
								+ vo.getWarden_id()
								+ ",'"
								+ vo.getWarden_name()
								+ "',"
								+ vo.getCapacity()
								+  ")";
						System.out.println(query);
						c.dml(query);
					++count;

				}
				addActionError(count + " records are inserted successfully");
				return SUCCESS;
			}

			return ERROR;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
	}
}
